package com.qianyu.entity.dto;


import com.qianyu.entity.base.BaseIdDto;
import com.qianyu.entity.base.PageDTO;
import com.qianyu.util.MD5Util;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.springframework.util.ObjectUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;

/**
 * @author wangzhicheng
 * @date 2024/1/22 14:49
 * @description TODO
 */
@ApiModel(value = "用户dto")
public class UserDTO {

    /**
     * @author wangzhicheng
     * @date 2024/1/22 9:43
     * @description TODO
     */
    @ApiModel(value = "UserDTO&UserLoginDTO")
    @Data
    public static class UserLoginDTO {
        /**
         * 用户名
         */
        @ApiModelProperty(value = "用户名", required = true)
        @NotBlank
        private String username;
        /**
         * 密码
         */
        @ApiModelProperty(value = "密码", required = true)
        @NotBlank
        private String password;
    }

    /**
     * @author wangzhicheng
     * @date 2024/1/22 9:43
     * @description TODO
     */
    @ApiModel(value = "UserDTO&UserRegisterDTO")
    @Data
    public static class UserRegisterDTO {
        /**
         * 用户名
         */
        @ApiModelProperty(value = "用户名", required = true)
        @NotBlank
        private String username;
        /**
         * 密码
         */
        @ApiModelProperty(value = "密码", required = true)
        @NotBlank
        private String password;

        /**
         * 二次密码
         */
        @ApiModelProperty(value = "二次密码", required = true)
        @NotBlank
        private String passwordTwo;

        public String getPassword() {
            if (!ObjectUtils.isEmpty(password)) {
                return MD5Util.md5(password);
            }
            return null;
        }

        public String getPasswordTwo() {
            if (!ObjectUtils.isEmpty(passwordTwo)) {
                return MD5Util.md5(passwordTwo);
            }
            return null;
        }
    }

    /**
     * @author wangzhicheng
     * @date 2024/1/22 14:46
     * @description TODO
     */
    @Data
    @ToString
    @ApiModel(value = "UserDTO&UserSaveDTO")
    public static class UserSaveDTO {
        /**
         * 登录名
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty(value = "登录名", required = true)
        @NotNull(message = "登录名不能为空")
        private String username;
        /**
         * 登录密码
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty(value = "登录密码", required = true)
        @NotNull(message = "登录密码不能为空")
        private String password;
        /**
         * 昵称
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty(value = "昵称", required = true)
        private String nickname;
        /**
         * 回收折扣比
         */
        @ApiModelProperty(value = "回收折扣比", required = true)
        private BigDecimal recycleRatio;
        /**
         * 日租金
         */
        @ApiModelProperty(value = "日租金", required = true)
        private BigDecimal dayRent;
        /**
         * 余额
         */
        @ApiModelProperty("余额")
        private BigDecimal money;
        /**
         * 备注
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty("备注")
        private String remark;

        public String getPassword() {
            if (!ObjectUtils.isEmpty(password)) {
                return MD5Util.md5(password);
            }
            return null;
        }
    }

    /**
     * 修改用户信息
     */
    @Data
    @ToString
    @ApiModel(value = "UserDTO&UserUpdateDTO")
    public static class UserUpdateDto extends BaseIdDto {
        /**
         * 登录名
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty(value = "登录名")
        private String username;
        /**
         * 昵称
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty(value = "昵称")
        private String nickname;
        /**
         * 备注
         */
        @Size(max = 255, message = "编码长度不能超过255")
        @ApiModelProperty("备注")
        private String remark;

        /**
         * 状态
         */
        @ApiModelProperty("-1 删除 0-禁用 1-正常")
        private Integer status;
    }

    @Data
    @ApiModel(value = "UserDTO$userPageDTO")
    public static class UserPageDTO extends PageDTO {
        /**
         * 姓名
         */
        @ApiModelProperty(value = "用户名或昵称")
        private String username;

    }

    @Data
    @ApiModel(value = "UserDTO$passwordDTO")
    public static class PasswordDto extends BaseIdDto{
        /**
         * 旧密码
         */
        @NotNull(message = "旧密码不能为空")
        @ApiModelProperty(value = "旧密码", required = true)
        private String odlPassword;

        /**
         * 新密码
         */
        @NotNull(message = "新密码不能为空")
        @ApiModelProperty(value = "新密码", required = true)
        private String newPassword;
    }

    @Data
    @ApiModel(value = "UserDTO$UserSimpleDTO")
    public static class UserSimpleDTO{
        /**
         * 用户id
         */
        private Long id;
        /**
         * 姓名
         */
        @ApiModelProperty(value = "昵称")
        private String nickname;

    }
}
